package main
/*
   该文件应该被打包成一个二进制文件，由平台调用该二进制中的方法，方法中检查是否存在server.crt等加密文件

   如果加密文件没问题，则返回加密ok，平台可以启动
*/
import (
	"context"
	"log"
	"net"

	"google.golang.org/grpc"
	pb "path/to/your/calculator" // 替换为你的包路径
	"google.golang.org/grpc/credentials"
	"crypto/tls"
	"crypto/x509"
)

type server struct {
	pb.UnimplementedCalculatorServiceServer
}

func (s *server) Add(ctx context.Context, req *pb.AddRequest) (*pb.AddResponse, error) {
	return &pb.AddResponse{Result: req.A + req.B}, nil
}


func main() {
	lis, err := net.Listen("tcp", ":50051")
	if err != nil {
		log.Fatalf("failed to listen: %v", err)
	}

	s := grpc.NewServer()
	pb.RegisterCalculatorServiceServer(s, &server{})
	log.Printf("server listening at %v", lis.Addr())
	if err := s.Serve(lis); err != nil {
		log.Fatalf("failed to serve: %v", err)
	}
	creds, err := credentials.NewServerTLSFromFile("server.crt", "server.key")
	if err != nil {
		log.Fatalf("failed to load TLS: %v", err)
	}

	s := grpc.NewServer(grpc.Creds(creds))
	// ... 注册服务
}

